package com.zgkj.Zip.tools;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
/**
 * dao接口
 * @author caoyaojun
 * @adddate 2010-10-9
 *
 */
public interface DBUtilI {

	/**
	 * 功能：获得已经创建好的数据库链接
	 * @param
	 * @return    Connection
	 * @exception 获取数据源错
	 */
	public abstract Connection getConnection();

	/**
	 * 功能：获得已经创建好的数据库链接
	 * @param
	 * @return    Statement
	 */
	public abstract Statement getQryStatement();

	public abstract Statement getUptStatement() throws SQLException;

	public abstract ResultSet query(String sql) throws SQLException;

	public abstract int update(String sql) throws SQLException;

	public abstract int update(String sql, int code) throws SQLException;

	public abstract void addBatch(String sql) throws SQLException;

	public abstract void addBatch(ArrayList<String> list) throws SQLException;

	public abstract int executeBatch() throws SQLException;

	/*
	 * code 0:判断所有的sql是否成功
	 *      1:执行过程中不出错就可以
	 */
	public abstract int executeBatch(int code) throws SQLException;

	public abstract void commit() throws SQLException;

	public abstract void rollback() throws SQLException;

	public abstract void close();

	/**
	 * 功能：获取数据库一个参数的值
	 * @param     String sql
	 * @return    ArrayList
	 */
	public abstract ArrayList getOneParValueByArrayList(String sql)
			throws SQLException;

	/**
	 * 功能：获取数据库一个参数的值
	 * @param     String sql
	 * @return    String[]
	 */

	public abstract String[] getOneValueByStringArray(String sql)
			throws SQLException;

	/**
	 * 功能：获取数据库一个参数的值
	 * @param     String sql
	 * @return    String[]
	 */

	public abstract String[] getOneNoteValuesByStringArray(String sql)
			throws SQLException;

	/**
	 * 功能：获取最大值
	 * @param     String sql
	 * @return    String[]
	 */
	public abstract int getMaxValue(String sql) throws SQLException, Exception;

	/**
	 * 功能：获取最大值
	 * @param     String sql
	 * @return    String[]
	 */
	public abstract long getMaxValueByLong(String sql) throws SQLException,
			Exception;

	/**
	 * 功能：获取最大值
	 * @param     String sql
	 * @return    String[]
	 */
	public abstract Integer getMaxValue2(String sql) throws SQLException,
			Exception;

	public abstract int getOneNoteOneParValue(String sql, int num)
			throws SQLException, Exception;

	public abstract long getOneNoteOneParValueByLong(String sql, int num)
			throws SQLException, Exception;

	public abstract String getOneNoteOneParValue(String sql)
			throws SQLException, Exception;

	/**
	 * 功能：返回查询结果集
	 * @param     String sql
	 * @return    String[][]
	 * @exception
	 */
	public abstract String[][] getParValuesByArray(String sql)
			throws SQLException;

	/**
	 * 功能：返回查询结果集
	 * @param     String sql
	 * @return    String[][]
	 * @exception
	 */
	public abstract String[][] getParValuesByArray(String sql, int length)
			throws SQLException;

	public abstract ArrayList getParValuesByArrayList(String sql)
			throws SQLException;

	public abstract ArrayList getStatParValuesByArrayList(String sql)
			throws SQLException;

	public abstract int getStatParValuesByArrayList(String sql, ArrayList list)
			throws SQLException;

	/**
	 * 功能：返回查询结果集
	 * @param     String sql
	 * @return    ArrayList
	 * @exception
	 */
	public abstract ArrayList getOneValuesByArrayList(String sql)
			throws SQLException;

	/**
	 * 功能：返回查询结果集
	 * @param     String sql
	 * @return    ArrayList
	 * @exception
	 */
	public abstract ArrayList getOneValuesByArrayList(String sql,
			String firstValue, int code) throws SQLException;

	public abstract ArrayList getOneValuesByArrayList(String sql,
			String firstValue) throws SQLException;

	public abstract ArrayList getOneValuesByArrayList(String sql,
			ArrayList firstValue) throws SQLException;

	/**
	 * 功能：将单条记录封装成HashMap形式返回，Key为字段名,value为字段值
	 * @param     ResultSet，结果集
	 * @return    HashMap
	 * @exception
	 */
	public abstract HashMap getRecord(String sql) throws SQLException;

	/**
	 * 功能：将单条记录封装成HashMap形式返回，Key为字段名,value为字段值
	 * @param     ResultSet，结果集 HashMap hm
	 * @return    HashMap  0:结果为空 1：查询到结果
	 * @exception
	 */
	public abstract int getRecordHm(String sql, HashMap hm) throws SQLException;

	/**
	 * 功能：将[n]记录封装成HashMap[]形式返回，Key为字段名,value为字段值
	 * @param     ResultSet，结果集
	 * @return    HashMap
	 * @exception
	 */
	public abstract HashMap[] getRecordHashMapArray(String sql)
			throws SQLException;

	/**
	 * 功能：将两参数的记录结果封装成HashMap形式返回，Key为id,value为name
	 * @param     ResultSet，结果集
	 * @return    HashMap
	 * @exception
	 */
	public abstract HashMap getIdToName(String sql) throws SQLException;

	public abstract int getCount(String sql) throws SQLException;

	public abstract boolean isResultNull(String sql) throws SQLException;

	/**
	 * 功能：将双参数封录封装成HashMap(String key，String value)形式返回，双字段
	 * @param     ResultSet，结果集
	 * @return    HashMap
	 * @exception
	 */
	public abstract HashMap getTwoFieldKeyByValue(String sql)
			throws SQLException;

	/**
	 * 功能：将双参数封装成HashMap(String key，ArrayList value)形式返回，双字段
	 * @param     ResultSet，结果集
	 * @return    HashMap
	 * @exception
	 */
	public abstract HashMap getTwoFieldKeyByValues(String sql)
			throws SQLException;

	/**
	 * 功能：将单条记录封装成HashMap形式返回,参数1为key,参数2,3,4...在ArrayList里面为value
	 * @param     ResultSet，结果集
	 * @return    HashMap
	 * @exception
	 */
	public abstract HashMap getIdToNote(String sql) throws SQLException;

	/**
	 * 功能：将单条记录封装成String[n][2]形式返回 String[n][0]:字段名称 String[n][1]:值
	 * @param     ResultSet，结果集
	 * @return     结果为空时返回null;
	 * @throws SQLException
	 * @exception
	 * @author
	 */

	public abstract String[][] getOneNoteByFieldToValue(String sql)
			throws SQLException;

	public abstract int getNumber(String sql) throws SQLException;

	public abstract long getLongNumber(String sql) throws SQLException;

}